package com.gqz.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gqz.domain.SysOperLog;
import com.gqz.mapper.SysOperLogMapper;
import com.gqz.query.BaseQuery;
import com.gqz.service.ISysOperLogService;
import com.gqz.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

@Service
public class SysOperLogServiceImpl implements ISysOperLogService {

    @Autowired
    private SysOperLogMapper sysOperLogMapper;

    @Override
    public PageList<SysOperLog> getAllOperLog(BaseQuery query) {
        Example example = new Example(SysOperLog.class);
        if (query.getKeyword() != null) {
            example.or().orLike("realName", "%" + query.getKeyword() + "%");
            example.or().orLike("content", "%" + query.getKeyword() + "%");
        }

        PageHelper.startPage(query.getPageIndex(), query.getPageSize());

        PageInfo<SysOperLog> sysOperLogPageInfo = new PageInfo<>(sysOperLogMapper.selectByExample(example));

        PageList<SysOperLog> list = new PageList<>(sysOperLogPageInfo.getTotal(), sysOperLogPageInfo.getList());

        return list;
    }

    @Override
    public boolean deleteOperLog(Long id) {
        return sysOperLogMapper.deleteByPrimaryKey(id) > 0;
    }

    @Override
    public boolean batchDeleteOperLog(Long[] ids) {
        return sysOperLogMapper.batchDeleteOperLog(ids) > 0;
    }

    @Override
    public boolean updateOperLog(SysOperLog sysOperLog) {
        return sysOperLogMapper.updateByPrimaryKey(sysOperLog) > 0;
    }

    @Override
    public boolean insertOperLog(SysOperLog sysOperLog) {
        return sysOperLogMapper.insert(sysOperLog) > 0;
    }
}
